You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
750 B
24 lines
750 B
import { toggleTask } from "../../../../service/scheduler";
|
|
import { reloadTask, removeTask } from "../../../../scheduler/engine";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const id = getRouterParam(event, "id");
|
|
if (!id) return R.throwError(400, "Missing id", null);
|
|
|
|
const body = await readBody<{ enabled: boolean }>(event);
|
|
|
|
const task = await toggleTask(id, body.enabled);
|
|
if (!task) return R.throwError(404, "Task not found", null);
|
|
|
|
if (task.enabled) {
|
|
reloadTask(id);
|
|
} else {
|
|
removeTask(id);
|
|
}
|
|
|
|
await event.context.cache.del(`scheduler:task:${id}`)
|
|
await event.context.cache.del('scheduler:tasks:1:20:all:all')
|
|
await event.context.cache.del('scheduler:stats')
|
|
|
|
return R.success(task);
|
|
});
|